﻿using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using DevExpress.XtraReports.UI;
using FlyHorse.LIMS.Model;
using System.Collections.Generic;
using System.Linq;

namespace FlyHorse.LIMS.WinApp.XtraReportTemplate
{
    public partial class XtraReportRaw : DevExpress.XtraReports.UI.XtraReport
    {
        public XtraReportRaw(ReportRaw reportRaw)
        {
            InitializeComponent();
            InitReport(reportRaw);
        }

        private void InitReport(ReportRaw report)
        {
            xrLabel_NO.Text = "报告编号:"+report.SampleNO;

            xrTableCell_GoodsName.Text = report.Good.GoodsName;
            xrTableCell_ProductionUnit.Text = report.ProductionUnit;

            xrTableCell_SampleSendPerson.Text = report.SampleSendPerson;
            xrTableCell_SendDate.Text = report.SendDate.ToShortDateString();

            // xrTableCell_TestObjectives.Text = report.TestObjectives;
            xrTableCell_BatchNumber.Text = report.BatchNumber;

            xrTableCell16.Text = report.Conclusion;
            xrTableCell17.Text += "\r\n"+report.Remark;
            xrTableCell19.Text = report.PlateNumber;

            List<FlyHorse.LIMS.WinApp.Model.ReportRawResultPrintModel> resList = new List<FlyHorse.LIMS.WinApp.Model.ReportRawResultPrintModel>();

            foreach (var item in report.ReportRawResults)
            {
                FlyHorse.LIMS.WinApp.Model.ReportRawResultPrintModel res = new FlyHorse.LIMS.WinApp.Model.ReportRawResultPrintModel();
                res.Basis = item.Basis;
                res.ChineseName = item.ChineseName;
                if (String.IsNullOrEmpty(item.Conclusion))
                {
                    res.Conclusion = "-";
                }
                else
                {
                    res.Conclusion = item.Conclusion;
                }
                res.FormOrder = item.FormOrder;
                res.GUID = item.ReportRawResultID;
                if (String.IsNullOrEmpty(item.MaxValue))
                {
                    res.MaxValue = "-";
                }
                else
                {
                    res.MaxValue = item.MaxValue.ToString();
                }
                if (String.IsNullOrEmpty(item.MinValue))
                {
                    res.MinValue = "-";
                }
                else
                {
                    res.MinValue = item.MinValue.ToString();
                }
                res.ReportRawID = item.ReportRawID;
                res.testItem = item.TestItem;
                res.TestItemID = item.TestItemID;
                if (!String.IsNullOrEmpty(item.TestValue))
                {
                    res.TestValue = item.TestValue.ToString();
                }
                else
                {
                    res.TestValue = "";
                }
                res.Unit = item.Unit;
                resList.Add(res);
            }
            resList = resList.OrderBy(m => m.FormOrder).ToList();

            this.DataSource = resList;

            xrTableCell_TestItemName.DataBindings.Add("Text", null, "ChineseName");
            xrTableCell_Basis.DataBindings.Add("Text", null, "Basis");
            xrTableCell_Unit.DataBindings.Add("Text", null, "Unit");
            xrTableCell_MinValue.DataBindings.Add("Text", null, "MinValue");
            xrTableCell_MaxValue.DataBindings.Add("Text", null, "MaxValue");
            xrTableCell_TestValue.DataBindings.Add("Text", null, "TestValue");
            xrTableCell_Conclusion.DataBindings.Add("Text", null, "Conclusion");


        }

    }
}
